package com.spring.appservice.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.fasterxml.jackson.databind.util.JSONPObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.mangofactory.swagger.annotations.ApiIgnore;
import com.spring.appservice.web.service.BabyTreeService;
import com.spring.security.core.util.ApplicationUtils;

/**
 * 留言板
 * @author wojunyu
 *
 */
@Controller
@RequestMapping(value = "/babyTree")
@ApiIgnore
public class BabyTreeController {
	
	@Resource
	private BabyTreeService babyTreeService;
	

	/**
	 * 创建通道
	 * @param token
	 * @param msg_id
	 * @param request
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/createGrowthRecord")
	@ResponseBody
	public Object createGrowthRecord(String token, String recordTime, 
			String title, String content, String cUserID, MultipartFile file, String callback) {
		Map<String, Object> m = new HashMap();
		try {
			m = babyTreeService.createGrowthRecord(token, recordTime, title, content, cUserID, file);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	/**
	 * 得到生成成长记录
	 * @param token
	 * @param cUserID
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getGrowthRecordList")
	@ResponseBody
	public Object getGrowthRecordList(String token, String cUserID, String page_size, 
			String page_index, String skip, String rows, String callback) {
		
		Map<String, Object> m = new HashMap();
		try {
			m = babyTreeService.getGrowthRecordList(token, cUserID, page_size, page_index, skip, rows);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}

	/**
	 * 生成成长数据	
	 * @param token
	 * @param babyBirthday
	 * @param recordTime
	 * @param math
	 * @param growthDateTypeCode
	 * @param cUserID
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/createGrowthDate")
	@ResponseBody
	public Object createGrowthDate(String token, String babyBirthday, String recordTime,
			String data, String cUserID, String callback) {
		
		Map<String, Object> m = new HashMap();
		try {
			m = babyTreeService.createGrowthDate(token, babyBirthday, recordTime, data, cUserID);
			
		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	/**
	 * 得到成长数据
	 * @param token
	 * @param cUserID
	 * @param growthDateTypeCode
	 * @param page_size
	 * @param page_index
	 * @param skip
	 * @param rows
	 * @param callback
	 * @return
	 */
	@RequestMapping(value = "/getGrowthDateList")
	@ResponseBody
	public Object getGrowthDateList(String token, String cUserID, String growthDateTypeCode,String page_size,
			String page_index, String skip, String rows, String callback) {

		Map<String, Object> m = new HashMap();
		try {
			m = babyTreeService.getGrowthDate(token, cUserID, growthDateTypeCode, page_size, page_index, skip, rows);

		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	

	
	
	@RequestMapping(value = "/getNormalGrowthDateList")
	@ResponseBody
	public Object getNormalGrowthDateList(String growthDateTypeCode, String callback) {

		Map<String, Object> m = new HashMap();
		try {
			m = babyTreeService.getNormalGrowthDateList(growthDateTypeCode);

		} catch (Exception e) {
			e.printStackTrace();
			m.put(ApplicationUtils.STATUS, "0");
			m.put(ApplicationUtils.MSG, "系统异常");
		}

		if (ApplicationUtils.isNotNull(callback)) {
			return new JSONPObject(callback, m);
		} else {
			return m;
		}
	}
	
	
}
